<?php

/**
 * contenido actions.
 *
 * @package    corpon
 * @subpackage contenido
 * @author     Your name here
 * @version    SVN: $Id: actions.class.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class contentActions extends sfActions
{
 /**
  * Executes index action
  *
  * @param sfRequest $request A request object
  */
  public function executeIndex(sfWebRequest $request)
  {
    /* $this->noticias = Doctrine::getTable('Noticia')
      ->createQuery('a')
	  ->limit(5)
      ->execute();*/
  }
  
  public function executeAbout(sfWebRequest $request)
  {
  
  }
  
  public function executeFaq(sfWebRequest $request)
  {
  	
  }

  public function executeTerms(sfWebRequest $request)
  {

  }
  
  public function executeContact(sfWebRequest $request)
  {
    //$this->usuario = Doctrine::getTable('Usuario')->find(array($this->getUser()->getAttribute('id_usuario')));
            $today = date('Y-m-d');
      $this->products = Doctrine::getTable('Product')
                ->createQuery('p')
                ->select('p.*')
                ->where('p.status = 1')
                ->andWhere('p.start_date <= ?',$today)
                ->andWhere('p.end_date >= ?',$today)
                ->orderBy('Rand()')
                ->limit('4')
                ->execute();
  }
  
  public function executeSendMail(sfWebRequest $request)
  {
    // send an email to the affiliate
    $transport = Swift_SmtpTransport::newInstance('ssl://smtp.gmail.com', 465)
  		->setUsername('no-reply@corppon.com')
  		->setPassword('c0rpp0n20011');

    $sub = utf8_encode('CorpPon - Contact');
    $from = utf8_encode('CorpPon - Contact');

    $mailer = Swift_Mailer::newInstance($transport);

    $message = Swift_Message::newInstance()
	->setCharset('utf-8')

	//Give the message a subject
	->setSubject($sub)

	//Set the From address with an associative array
	->setFrom(array($request->getParameter('email') => $from))

	//Set the To addresses with an associative array
	->setTo(array('info@corppon.com' => $from))

        //Give it a body
	->setBody('You have received a message from '.$request->getParameter('name').',
            with email '.$request->getParameter('email').'
                and phone number '.$request->getParameter('phone').'<br/> <br/>
            Comment:<br/>
            '.$request->getParameter('comment'), 'text/html');

	//Send the message
	$result = $mailer->send($message);
 
    $this->redirect('content/contact?sent=1');
  }
}
